package com.nbcb.fund.web;

import com.nbcb.fund.entity.dto.FundResult;
import com.nbcb.fund.entity.po.ChinamutualFundNavPo;
import com.nbcb.fund.entity.vo.FundDetailVo;
import com.nbcb.fund.entity.vo.MyFundVo;
import com.nbcb.fund.service.ChinamutualFundService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api
@RestController
@RequestMapping("chinamutualfund")
public class ChinamutualFundController {

    @Autowired
    ChinamutualFundService chinamutualFundService;


    @ApiOperation("我的自选基金列表")
    @GetMapping("myfund")
    public FundResult<List<MyFundVo>> listMyFund() {
        List<MyFundVo> myFundVoList = chinamutualFundService.listMyFund();
        return FundResult.success(myFundVoList);
    }

    @ApiOperation("所有基金列表")
    @GetMapping("allfund")
    public FundResult<List<MyFundVo>> listAllFund() {
        List<MyFundVo> myFundVoList = chinamutualFundService.listAllFund();
        return FundResult.success(myFundVoList);
    }

    @ApiOperation("搜索我要关注的基金")
    @GetMapping("searchMyFund")
    public FundResult<MyFundVo> searchMyFund(@RequestParam("fInfoWindcode") String fInfoWindcode) {
        MyFundVo myFundVo = chinamutualFundService.getByWindCode(fInfoWindcode);
        return FundResult.success(myFundVo);
    }

    @ApiOperation("添加为我的自选")
    @PostMapping("addmyfund")
    public FundResult addMyFund(@RequestBody MyFundVo myFundVo) {
        String fInfoWindcode = myFundVo.getFInfoWindcode();
        int i = chinamutualFundService.addMyFund(fInfoWindcode);
        return FundResult.success(i);
    }

    @ApiOperation("从我的自选中删除")
    @PostMapping("deletemyfund")
    public FundResult deleteMyFund(@RequestParam("finfoWindcode") String finfoWindcode) {
        int i = chinamutualFundService.deleteMyFund(finfoWindcode);
        return FundResult.success(i);
    }

    @ApiOperation("基金信息详情展示")
    @GetMapping("fundDetail")
    public FundResult<FundDetailVo> fundDetail(@RequestParam("fInfoWindcode") String fInfoWindcode) {
        FundDetailVo fundDetailVo = chinamutualFundService.getFundDetailByWindCode(fInfoWindcode);
        return FundResult.success(fundDetailVo);
    }

    @ApiOperation("基金历史净值信息展示")
    @GetMapping("fundHistoryNav")
    public FundResult fundHistoryNav(@RequestParam("fInfoWindcode") String fInfoWindcode) {
        List<ChinamutualFundNavPo> list = chinamutualFundService.fundHistoryNav(fInfoWindcode);
        return FundResult.success(list);
    }

}
